package com.ams.controller;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ams.constants.WebConstant;
import com.ams.util.ValidationCodeUtil;

@Controller
@RequestMapping("/captcha")
public class CaptchaController {
	@RequestMapping("/change")
	public void change(HttpSession session,HttpServletResponse response){
		String vCode=ValidationCodeUtil.getCode(response);
		session.setAttribute("vcode", vCode);
	}
	
	@RequestMapping(value="/checks",method=RequestMethod.POST)
	@ResponseBody
	public  String checks(String vCode,HttpSession session){
		String oldvCode= (String) session.getAttribute("vcode");
		if(!vCode.equalsIgnoreCase(oldvCode)){
			return WebConstant.CAPTCHA_FAIL;
		}else{
			return WebConstant.CAPTCHA_SUCCESS;
		}
	}
	
}
